package com.lanqiao.gxnushop.mapper;

import com.lanqiao.gxnushop.entity.Reviews;
import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Schema(description ="评价表")
@Mapper
public interface ReviewsMapper {

    @Schema(description ="添加评价")
    @Insert("insert into reviews(buyerId,comment,date,orderId,productId,rating,reviewId) values (#{buyerId},#{comment},now(),#{orderId},#{productId},#{rating},#{reviewId})")
    boolean add(Reviews reviews);

    @Schema(description ="删除评价")
    @Delete("delete from reviews where reviewId=#{reviewId}")
    boolean delete(String reviewsId);

    @Schema(description ="根据买家id查询评价")
    @Select("select * from reviews where buyerId=#{buyerId}")
    ArrayList<Reviews> findByBuyerId(String buyerId);

    @Schema(description ="根据评价id查询评价")
    @Select("select * from reviews where reviewId=#{reviewId}")
    Reviews findById(String reviewsId);

    @Schema(description ="更新评价")
    @Update("update reviews set comment=#{comment},rating=#{rating} where reviewId=#{reviewId}")
    boolean update(Reviews reviews);

    @Schema(description ="根据买家id和商品id查询评价")
    @Select("select * from reviews where buyerId=#{buyerId} AND productId=#{productId}")
    ArrayList<Reviews> findByBuyerIdAndProductId(String buyerId, String productId);

    @Schema(description ="根据商品id查询评价")
    @Select("select * from reviews where productId=#{productId}")
    ArrayList<Reviews> findByProductId(String productId);

}
